package com.crm.service.impl.orderManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.orderManager.CustomerOrderGiftRelationMapper;
import com.crm.model.entity.orderManager.CustomerOrderGiftRelation;
import com.crm.model.entity.orderManager.CustomerOrderGiftRelationExample;
import com.crm.service.orderManager.CustomerOrderGiftRelationDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luojie
 * @date 2021/3/17 22:09
 */
@Service
public class CustomerOrderGiftRelationDbServiceImpl implements CustomerOrderGiftRelationDbService {

    @Autowired
    CustomerOrderGiftRelationMapper customerOrderGiftRelationMapper;

    @Override
    public Boolean insertOrderGiftRelation(CustomerOrderGiftRelation customerOrderGiftRelation) {
        int num = customerOrderGiftRelationMapper.insertSelective(customerOrderGiftRelation);
        return num>0;
    }

    /**
     * 订单管理-订单列表-订单详情-赠品详情列表
     * @Author pym
     * @Date  2021/3/19 9:37
     * @param productOrderId
     * @return {@link {java.util.List<com.crm.model.entity.orderManager.CustomerOrderGiftRelation>}}
     */
    @Override
    public List<CustomerOrderGiftRelation> selectCustomerOrderGiftRelationList(String productOrderId) {
        CustomerOrderGiftRelationExample customerOrderGiftRelationExample = new CustomerOrderGiftRelationExample();
        CustomerOrderGiftRelationExample.Criteria criteria = customerOrderGiftRelationExample.createCriteria();
        customerOrderGiftRelationExample.setOrderByClause("create_tm desc");
        criteria.andProductOrderIdEqualTo(productOrderId);
        criteria.andDeleteStatusEqualTo((short) StatusCodeEnum.NORMAL_CODE.getState());
        return customerOrderGiftRelationMapper.selectByExample(customerOrderGiftRelationExample);
    }

    @Override
    public List<CustomerOrderGiftRelation> selectCustomerOrderGiftRelationByOrderIdAndGiftId(String productOrderId, String giftId) {
        CustomerOrderGiftRelationExample customerOrderGiftRelationExample = new CustomerOrderGiftRelationExample();
        CustomerOrderGiftRelationExample.Criteria criteria = customerOrderGiftRelationExample.createCriteria();
        customerOrderGiftRelationExample.setOrderByClause("create_tm desc");
        criteria.andProductOrderIdEqualTo(productOrderId);
        criteria.andProductGiftActivityIdEqualTo(giftId);
        criteria.andDeleteStatusEqualTo((short) StatusCodeEnum.NORMAL_CODE.getState());
        return customerOrderGiftRelationMapper.selectByExample(customerOrderGiftRelationExample);
    }

}
